package com.binvshe.binvshe.app.home;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.binvshe.binvshe.activity.ActivityEntity;
import com.binvshe.binvshe.app.home.adapter.HomeAdapter;
import com.binvshe.binvshe.common.http.ListDataRequestListener;
import com.binvshe.binvshe.common.http.MyHttpRequest;
import com.binvshe.binvshe.common.http.UrlCenter;
import com.binvshe.binvshe.entity.HomeEntity;
import com.pachong.android.baseuicomponent.adapter.RecyclerViewBaseAdapter;
import com.pachong.android.baseuicomponent.fragment.SwipeListFragment;
import com.pachong.android.framework.httprequest.IHttpRequest;
import com.pachong.android.framework.httprequest.UrlParams;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2017/2/3
 * 首页热门
 */

public class HotOpusFragment extends SwipeListFragment {

    private int mPage = 0;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        startLoading();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public RecyclerViewBaseAdapter createAdapter() {
        return new HomeAdapter(getContext());
    }

    @Override
    public void onStartLoading() {
        loadData();
    }

    private ListDataRequestListener<HomeEntity> mResponceListener = new ListDataRequestListener<>(this, HomeEntity.class, false);

    protected void loadData() {
        if (mPage==0||mResponceListener.getResponseDataParser().hasMore()) {
            mPage++;
            String url = UrlCenter.HOME_HOT;
            IHttpRequest request = new MyHttpRequest(getContext());
            UrlParams params = new UrlParams();
            params.put("size", 10 + "");
            params.put("page", mPage + "");
            request.get(url, params, mResponceListener);
        }
    }


    @Override
    public void onStartRefreshing() {
        super.onStartRefreshing();
        getData().clear();
        mPage = 0;
        startLoading();
    }

}
